package com.liuugoqing.behavioral.visitor.dynamicdispatch;

import org.junit.Test;

/**
 * 动态分派(Dynamic Dispatch) 发生在运行时期，动态分派动态地置换掉某
 * 个方法。Java通过方法的重写支持动态分派
 * @Author : liugq
 * @Date : 2022/7/15 21:42
 * @See : 参考类
 * @Since： JDK1.8
 * @Version : 1.0
 */

public class Client {

    public class Animal {
        public void execute() {
            System.out.println("Animal");
        }
    }

    public class Dog extends Animal {
        @Override
        public void execute() {
            System.out.println("dog");
        }
    }

    public class Cat extends Animal {
        @Override
        public void execute() {
            System.out.println("cat");
        }
    }


    @Test
    public void main() {
        Animal a = new Dog();
        a.execute();

        Animal a1 = new Cat();
        a1.execute();
    }
}
